layui.extend({
    dtree: '../../lib/dtree/dtree'
}).define(['jquery','dialog','upload','layedit','dtree'],function(exports){
    var $ = layui.jquery;
    var dialog = layui.dialog;
    var upload = layui.upload,
        dtree=layui.dtree,
        layedit = layui.layedit;
    var dtreeUtil = {
        baseDtree:function(obj,url,isCheck,successFn){
            if(isCheck==null||isCheck==""){
                isCheck=false;
            }
            var dTree=dtree.render({
                elem:obj,
                url: url,
                method:"post",
                dataStyle: "layuiStyle",  //使用layui风格的数据格式（非必须）
                dataFormat: "list",  //配置data的风格为list
                response:{message:"msg",statusCode:0},  //修改response中返回数据的定义
                icon: ["0","-1"],
                dot: false,// 使用
                checkbar:isCheck ,//开启复选框
                done: function(data, obj){
                    $("#search_btn").click(function(){
                        var value = $("#searchInput").val();
                        if(value){
                            var flag = dTree.searchNode(value); // 内置方法查找节点
                            if (!flag) {layer.msg("该关键字不存在！", {icon:5});}
                        } else {
                            dTree.menubarMethod().refreshTree(); // 内置方法刷新树
                        }
                    });
                    //通过回调函数设置值
                    if (typeof successFn == 'function') {
                        successFn(data,obj);
                    }
                }
            });
            return dTree;
        },
        pageDtree:function(obj,url,check,successFn){
            return this.baseDtree(obj,url,check,successFn);
        },
        dTreeClick:function(objId,successFn){
            // 点击节点触发回调
            dtree.on("node('"+objId+"')" ,function(param){
                successFn(param);
            });
        },
        getCheckbarNodesParam:function(objId,successFn){
            var params = dtree.getCheckbarNodesParam(objId);
            successFn(params);
        },
        chooseDataInit:function(objId,ids){
            dtree.chooseDataInit(objId,ids);
        }


    };
    //输出baseutil接口
    exports('dtreeUtil', dtreeUtil);
});



